package highTech.proxy.proxyMethod;

import highTech.proxy.proxyClass.Advice;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyMethod {
	public static Object getProxy(final Object target,final Advice advice){
		return Proxy.newProxyInstance(
				target.getClass().getClassLoader(),
				target.getClass().getInterfaces(),
				new InvocationHandler(){

					@Override
					public Object invoke(Object proxy, Method method,
							Object[] args) throws Throwable {
						advice.beforeMethod(method);
						Object retVal=method.invoke(target, args);
						advice.afterMethod(method);
						return retVal;
					}
					
				});
	}

}
